import {ref} from 'vue'
import {listByParentCode} from "@/api/nongjt/area"
export function areaSelect() {
    // 省份列表
    const provinceList = ref([])
    // 市列表
    const cityList = ref([])
    // 区县列表
    const areaList = ref([])
    // 街道列表
    const streetList = ref([])
    // 初始化省
    const initProvinceList = () => {
        listByParentCode().then(res => {
            provinceList.value = res.data
        })
    }
    // 选择省改变
    const provinceChange = (parentCode) => {
        listByParentCode({parentCode}).then(res => {
            cityList.value = res.data
        })
    }
    // 选择市改变
    const cityChange = (parentCode) => {
        listByParentCode({parentCode}).then(res => {
            areaList.value = res.data
        })
    }
    // 选择区改变
    const areaChange = (parentCode) => {
        listByParentCode({parentCode}).then(res => {
            streetList.value = res.data
        })
    }
    // 重置
    const resetAreaList = () => {
        cityList.value = []
        areaList.value = []
        streetList.value = []
    }
    return {
        provinceList,
        cityList,
        areaList,
        streetList,
        initProvinceList,
        provinceChange,
        cityChange,
        areaChange,
        resetAreaList
    }
}